<template>

    <el-col :span="span" v-show="showow">
      <div class="comwidth">
        <lableName    :validrule="validrule"
          :curLabelName="curLabelName"
          :isShowLabel="isShowLabel"
          :isRequire="false"
        ></lableName>

        <el-select
          :multiple="isMul"
          collapse-tags
          :filterable="filterable"
          v-model="modelCode"
          placeholder="请选择"
          @clear="clearCode"
          :clearable="clearable"
          @change="sendCode1"
          :disabled="disabled"
          :readonly="readonly"
          size="small"
        >
          <el-option
            v-for="item in optionDatas"
            :key="item[optionFields.length > 1 ? optionFields[0] : defOptionFields[0]]"
            :label="item[optionFields.length > 1 ? optionFields[1] : defOptionFields[1]]"
            :value="item[optionFields.length > 1 ? optionFields[0] : defOptionFields[0]]"
          >{{item[optionFields.length > 1 ? optionFields[1] : defOptionFields[1]]}}</el-option>
        </el-select>
        <validateFormate
          :curLabelName="curLabelName"
          :validrule="validrule"
        ></validateFormate>
      </div>
    </el-col>
</template>
<script>
import { crmApis } from "@/api/apiList/crm";
import { dropdownMixins } from "@/components/mixins/dropdownMixins";
// import lableName from "@/components/lableName";
// import validateFormate from "@/components/validateFormate";
export default {
  name: "lookupValue",
  // 组件混入对象：{props[span,isShowLabel,code,isMul,labelName] data[modelCode,optionDatas,listQuery] methods[queryTable,sendCode]}
  mixins: [dropdownMixins],
  components: {
    lableName: () => import("@/components/lableName"), //标题溢出样式组件
    validateFormate: () => import("@/components/validateFormate"), //校验提示样式组件
  },
  props: {
    // 值列表类型编码
    lookuptype: { type: String, default: "_is_null_code_" },
    // 获取组件中的名称，如：textField="carBrandCode"
    codeField: { type: String, default: "lookupValueCode" },
    // 获取组件中的名称，如：textField="carBrandName"
    textField: { type: String, default: "lookupValueName" },
    show:{type:Boolean,default:true}
  },
  data() {
    return {
      showow:this.show,
      unit:"",
      // 默认绑定数据对象字段
      defOptionFields: ['lookupValueCode', 'lookupValueName'],
      // API配置对象
      apiConfig: crmApis.mdsLookupValueQueryByPage,
      // 表格中台返回网格的字段
      apiQueryRow: [
        "oemCode",
        "groupCode",
        "lookupTypeCode",
        "lookupValueCode",
        "lookupValueName"
      ],
      // 下拉查询条件
      listQuery: {
        isEnable: "",
        lookupTypeCode: this.lookuptype
      }
      //   curLabelName: this.label
    };
  },
  methods:{
    sendCode1(value){
      let val=this.modelCode;
      let text=this.codeField
      this.$emit("changeCode", val,text);
      this.$emit("sendChangeCodeCAO", val,text);
      let that = this;
      let option = that.optionDatas;
      let j = value;
      for (var i = 0; i < option.length; i++) {
        if (option[i].lookupValueCode == j) {
          let name = option[i].lookupValueName;
          this.$emit("changeDropValue", j, name, that.codeField, that.textField);
        }
      }
      this.sendCode()
    }
  }

};
</script>
